/**
 * Copyright 2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * ChunMap是开源软件。你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。
 * 
 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 * 
 * 下面此段程序作者YangJianDong(chunquedong)
 * 最后修改时间2010.7.17
 */
package chunmap.app.bench;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;


public class ComponentUtils {
	public static void bindEvent(final OperateManager mapboxListener,Component component) {
		component.addMouseWheelListener(new MouseWheelListener() {
			@Override
			public void mouseWheelMoved(MouseWheelEvent e) {
				mapboxListener.onEvent(e, EventType.MouseWheel);
			}
		});
		component.addMouseListener(new MouseListener() {
	
			@Override
			public void mouseClicked(MouseEvent e) {
				if(e.getClickCount()>1){
					mapboxListener.onEvent(e, EventType.MouseDoubleClick);
				}else{
					mapboxListener.onEvent(e, EventType.MouseClik);
				}
			}
	
			@Override
			public void mouseEntered(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseEntered);
			}
	
			@Override
			public void mouseExited(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseExited);
			}
	
			@Override
			public void mousePressed(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseDown);
			}
	
			@Override
			public void mouseReleased(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.KeyUp);
			}
	
		});
		component.addMouseMotionListener(new MouseMotionListener() {
			@Override
			public void mouseDragged(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseDragged);
			}
	
			@Override
			public void mouseMoved(MouseEvent e) {
				mapboxListener.onEvent(e, EventType.MouseMove);
			}
		});
		component.addKeyListener(new KeyListener() {
	
			@Override
			public void keyPressed(KeyEvent e) {
				mapboxListener.onEvent(e, EventType.KeyDown);
			}
	
			@Override
			public void keyReleased(KeyEvent e) {
				mapboxListener.onEvent(e, EventType.KeyUp);
			}
	
			@Override
			public void keyTyped(KeyEvent e) {
				mapboxListener.onEvent(e, EventType.Unknow);
			}
		});
	}
}
